package xyz.scootaloo.oj.iq

import org.junit.Test
import xyz.scootaloo.console.app.support.Tester

/**
 * @author flutterdash@qq.com
 * @since 2021/4/15 8:56
 */
class M0102 {

    private fun CheckPermutation(s1: String, s2: String): Boolean {
        if (s1.length != s2.length)
            return false
        val cache = IntArray(26)
        for (c in s1) {
            val offset = c - 'a'
            cache[offset]++
        }

        for (c in s2) {
            val offset = c - 'a'
            if (cache[offset] > 0) {
                cache[offset]--
            } else {
                return false
            }
        }

        return true
    }

    @Test
    fun test0() {
        println(CheckPermutation("abc", "bca"))
        println(CheckPermutation("abc", "bad"))
    }

}
